package service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import mapper.PersonMapper;
import model.DemoPojo;
import model.Person;
import org.springframework.stereotype.Service;
import pojo.PersonHobby;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by walter on 2016/3/29.
 */
@Service
public class PersonService {
    @Resource
    private PersonMapper personMapper;

    public Integer add(Person person){
        System.out.println(person.getName());
        System.out.println(person.getGender());
        return personMapper.insert(person);
    }

    public Person findOne(Integer id){
        return  personMapper.selectByPrimaryKey(id);
    }

    public Integer modify(Person person){
        return  personMapper.insertSelective(person);
    }

    public Integer delete(Integer id){
        return  personMapper.deleteByPrimaryKey(id);
    }

    public List<Person> page(Integer start,Integer pageSize){
        List<Person> list = personMapper.page(start,pageSize);
        for (Person p:list) {
            System.out.println(p.getName());
        }
        return list;
    }

    public PageInfo<Person> pageByPlugins(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Person> list = personMapper.pageByPlugins();
        return new PageInfo(list);
    }

    public PageInfo<DemoPojo> all(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<DemoPojo> list = personMapper.all();
        return new PageInfo(list);
    }

    public List<PersonHobby> findByPersonId(Integer id){
        return this.personMapper.findHooby(id);
    }
}
